using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class FPS : MonoBehaviour
{
    public float UpdateInterval = 1;
    private Text text;
    private int frames;
    private int fps;
    // Use this for initialization
    void Start()
    {
        Application.targetFrameRate = 1000;
        text = GetComponent<Text>();
        InvokeRepeating("UpdateFPS", UpdateInterval, UpdateInterval);
    }

    void UpdateFPS()
    {

        fps = frames;
        if (text != null)
        {
            if (frames < 30) text.color = Color.red;
            if (frames >= 30 && frames <= 50) text.color = Color.yellow;
            else text.color = Color.green;
            text.text = string.Format("FPS: {0:F2}", fps);
        }
        frames = 0;
    }
    void OnGUI()
    {
        GUI.Label(new Rect(0, 0, 100, 40), string.Format("FPS: {0:F2}", fps));
    }

    // Update is called once per frame
    void Update()
    {
        frames++;
    }
}
